﻿using Microsoft.Phone.Controls;
using CDFWPUG.Model;
using CDFWPUG.ViewModel;
using GalaSoft.MvvmLight.Messaging;
using System;
using Microsoft.Phone.Controls.Maps;
using System.Windows;

namespace CDFWPUG.Views
{
    /// <summary>
    /// Description for pageMeeting.
    /// </summary>
    public partial class pageMeeting : PhoneApplicationPage
    {
        /// <summary>
        /// Initializes a new instance of the pageMeeting class.
        /// </summary>
        public pageMeeting()
        {
            InitializeComponent();
            Messenger.Default.Register<Uri>(this, "NavigationRequest", (uri) => NavigationService.Navigate(uri));
            Messenger.Default.Register<String>(this, "MessageBoxRequest", (message) => MessageBox.Show(message));
            
        }

        private void chkReminder_Checked(object sender, System.Windows.RoutedEventArgs e)
        {
            chkReminder.Content = "on";
        }

        private void chkReminder_Unchecked(object sender, System.Windows.RoutedEventArgs e)
        {
            chkReminder.Content = "off";
        }

        private void btnPinToStart_Click(object sender, System.EventArgs e)
        {
            var vm = DataContext as pageMeetingViewModel;
            if (vm != null)
            {
                vm.PinToStartCommand.Execute(null);
            }
        }

       

        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            Dispatcher.BeginInvoke(() =>
            {
                var ID = NavigationContext.QueryString["MeetingID"];
                var viewModel =  DataContext as pageMeetingViewModel;
                viewModel.LoadMeeting(Convert.ToInt32(ID));
            });

            listLocation.SelectedIndex = -1;
            base.OnNavigatedTo(e);
        }

        protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
        {
            Dispatcher.BeginInvoke(() =>
            {
               
                var viewModel = DataContext as pageMeetingViewModel;
                viewModel.Cleanup();
            });

            base.OnNavigatedFrom(e);
        }

        private void btnShare_Click(object sender, System.EventArgs e)
        {
            var vm = DataContext as pageMeetingViewModel;
            if (vm != null)
            {
                vm.ShareCommand.Execute(null);
            }
        }

     
    }
}